import { Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { ConfigService } from '@nestjs/config';
import { BaseService } from '@wwjCommon/base/base.service';
import { CacheService } from '@wwjCommon/cache/cache.service';
import { LoggingService } from '@wwjCommon/logging/logging.service';
import { UploadService } from '@wwjVendor/upload/upload.service';
import { PayService } from '@wwjVendor/pay/pay.service';
import { SmsService } from '@wwjVendor/sms/sms.service';
import { NoticeService } from '@wwjVendor/notice/notice.service';

@Injectable()
export class CoreNiuSmsService extends BaseService<any> {
  private readonly logger = new Logger(CoreNiuSmsService.name);

  constructor(
    @InjectRepository(Object)
    protected readonly repository: Repository<any>,
    private readonly cacheService: CacheService,
    private readonly configService: ConfigService,
    private readonly loggingService: LoggingService,
    private readonly uploadService: UploadService,
    private readonly payService: PayService,
    private readonly smsService: SmsService,
    private readonly noticeService: NoticeService,
  ) {
    super(repository);
  }

  /**
   * setSiteId
   * 对应 PHP: CoreNiuSmsService_core::setSiteId()
   * 逻辑类型: undefined - undefined
   */
  async setSiteId(site_id: string) {
    // 基于PHP真实逻辑: setSiteId
    // PHP原文: $this->site_id = $site_id;         return $this;     }      /**      * 设置账号缓存      * @param $params      * @return \app\model\sys\SysConfig|bool|\thin...
this.site_id = site_id;
        return this;
    }

    /**
     * 设置账号缓存
     * @param params
     * @return \app\model\sys\SysConfig|bool|\think\Model
     */
    async setNiuLoginConfig(params, is_login = false)
    {
        const config = this.setSiteId(this.site_id).getNiuLoginConfig(true];
        config.default = params.default || (config.default || ""];
        config[SmsDict.NIUSMS] = [
            username: params.username || config[SmsDict.NIUSMS].username || "",
            password: params.password || config[SmsDict.NIUSMS).password || "",
            signature: is_login ? "" : (params.signature || config[SmsDict.NIUSMS).signature || ""),//登录清空默认签名重新选择
        ];
        return this.coreConfigService.setConfig(this.site_id, ConfigKeyDict.SMS, config);
    }

    async getNiuLoginConfig(is_all = false)
    {
        const config = this.coreConfigService.getConfigValue(this.site_id, ConfigKeyDict.SMS);
        if (is_all) {
            return config;
  }

  /**
   * setNiuLoginConfig
   * 对应 PHP: CoreNiuSmsService_core::setNiuLoginConfig()
   * 逻辑类型: undefined - undefined
   */
  async setNiuLoginConfig(params: any, is_login: any) {
    // 基于PHP真实逻辑: setNiuLoginConfig
    // PHP原文: $config = $this->setSiteId($this->site_id)->getNiuLoginConfig(true);         $config['default'] = $params['default'] ?? ($config['default'] ?? "");   ...
const config = this.setSiteId(this.site_id).getNiuLoginConfig(true];
        config.default = params.default || (config.default || ""];
        config[SmsDict.NIUSMS] = [
            username: params.username || config[SmsDict.NIUSMS].username || "",
            password: params.password || config[SmsDict.NIUSMS).password || "",
            signature: is_login ? "" : (params.signature || config[SmsDict.NIUSMS).signature || ""),//登录清空默认签名重新选择
        ];
        return this.coreConfigService.setConfig(this.site_id, ConfigKeyDict.SMS, config);
    }

    async getNiuLoginConfig(is_all = false)
    {
        const config = this.coreConfigService.getConfigValue(this.site_id, ConfigKeyDict.SMS);
        if (is_all) {
            return config;
  }

  /**
   * getNiuLoginConfig
   * 对应 PHP: CoreNiuSmsService_core::getNiuLoginConfig()
   * 逻辑类型: undefined - undefined
   */
  async getNiuLoginConfig(is_all: any) {
    // 基于PHP真实逻辑: getNiuLoginConfig
    // PHP原文: $config = (new CoreConfigService())->getConfigValue($this->site_id, ConfigKeyDict::SMS);         if ($is_all) {             return $config;...
const config = this.coreConfigService.getConfigValue(this.site_id, ConfigKeyDict.SMS);
        if (is_all) {
            return config;
  }

  /**
   * packageList
   * 对应 PHP: CoreNiuSmsService_core::packageList()
   * 逻辑类型: undefined - undefined
   */
  async packageList(params: any) {
    // 基于PHP真实逻辑: packageList
    // PHP原文: $url = $this->niushop_url_prefix . self::PACKAGE_LIST_URL;         $res = (new HttpHelper())->get($url, $params + $this->getPageParam());         retu...
const url = this.niushop_url_prefix . self.PACKAGE_LIST_URL;
        const res = this.httpHelperService.get(url, params + this.getPageParam()];
        return res;
    }

    /**
     * 发验证短信
     * @param params
     * @return mixed
     */
    async sendMobileCode(params)
    {
        const url = this.niushop_url_prefix . self.SEND_CODE_URL;
        const res = this.httpHelperService.post(url, params);
        return res;
    }

    /**
     * 发验证短信
     * @return mixed
     */
    async captcha()
    {
        const url = this.niushop_url_prefix . self.SEND_CAPTCHA_URL;
        const res = this.httpHelperService.get(url);
        return res;
    }

    /**
     * 注册牛云短信子账号
     * @param params
     * @return mixed
     */
    async registerAccount(params)
    {
        const res = this.httpHelperService.post(this.niushop_url_prefix . self.ACCOUNT_REGISTER_URL, params);
        return res;
    }

    /**
     * 登录牛云短信子账号
     * @param params
     * @return mixed
     */
    async loginAccount(params)
    {
        const url = this.niushop_url_prefix . sprintf(self.LOGIN_ACCOUNT_URL, params.username];
        const res = this.httpHelperService.post(url, params);
        return res;
    }

    /**
     * 获取牛云短信子账号信息
     * @param username
     * @return mixed
     */
    async accountInfo(username)
    {
        const url = this.niushop_url_prefix . sprintf(self.ACCOUNT_INFO_URL, username];
        const res = this.httpHelperService.get(url);
        const config = this.setSiteId(this.site_id).getNiuLoginConfig(];
        if (config.username == res.username) {
            res.signature = config.signature || "";
  }

  /**
   * sendMobileCode
   * 对应 PHP: CoreNiuSmsService_core::sendMobileCode()
   * 逻辑类型: undefined - undefined
   */
  async sendMobileCode(params: any) {
    // 基于PHP真实逻辑: sendMobileCode
    // PHP原文: $url = $this->niushop_url_prefix . self::SEND_CODE_URL;         $res = (new HttpHelper())->post($url, $params);         return $res;     }      /**   ...
const url = this.niushop_url_prefix . self.SEND_CODE_URL;
        const res = this.httpHelperService.post(url, params);
        return res;
    }

    /**
     * 发验证短信
     * @return mixed
     */
    async captcha()
    {
        const url = this.niushop_url_prefix . self.SEND_CAPTCHA_URL;
        const res = this.httpHelperService.get(url);
        return res;
    }

    /**
     * 注册牛云短信子账号
     * @param params
     * @return mixed
     */
    async registerAccount(params)
    {
        const res = this.httpHelperService.post(this.niushop_url_prefix . self.ACCOUNT_REGISTER_URL, params);
        return res;
    }

    /**
     * 登录牛云短信子账号
     * @param params
     * @return mixed
     */
    async loginAccount(params)
    {
        const url = this.niushop_url_prefix . sprintf(self.LOGIN_ACCOUNT_URL, params.username];
        const res = this.httpHelperService.post(url, params);
        return res;
    }

    /**
     * 获取牛云短信子账号信息
     * @param username
     * @return mixed
     */
    async accountInfo(username)
    {
        const url = this.niushop_url_prefix . sprintf(self.ACCOUNT_INFO_URL, username];
        const res = this.httpHelperService.get(url);
        const config = this.setSiteId(this.site_id).getNiuLoginConfig(];
        if (config.username == res.username) {
            res.signature = config.signature || "";
  }

  /**
   * captcha
   * 对应 PHP: CoreNiuSmsService_core::captcha()
   * 逻辑类型: undefined - undefined
   */
  async captcha() {
    // 基于PHP真实逻辑: captcha
    // PHP原文: $url = $this->niushop_url_prefix . self::SEND_CAPTCHA_URL;         $res = (new HttpHelper())->get($url);         return $res;     }      /**      * 注册...
const url = this.niushop_url_prefix . self.SEND_CAPTCHA_URL;
        const res = this.httpHelperService.get(url);
        return res;
    }

    /**
     * 注册牛云短信子账号
     * @param params
     * @return mixed
     */
    async registerAccount(params)
    {
        const res = this.httpHelperService.post(this.niushop_url_prefix . self.ACCOUNT_REGISTER_URL, params);
        return res;
    }

    /**
     * 登录牛云短信子账号
     * @param params
     * @return mixed
     */
    async loginAccount(params)
    {
        const url = this.niushop_url_prefix . sprintf(self.LOGIN_ACCOUNT_URL, params.username];
        const res = this.httpHelperService.post(url, params);
        return res;
    }

    /**
     * 获取牛云短信子账号信息
     * @param username
     * @return mixed
     */
    async accountInfo(username)
    {
        const url = this.niushop_url_prefix . sprintf(self.ACCOUNT_INFO_URL, username];
        const res = this.httpHelperService.get(url);
        const config = this.setSiteId(this.site_id).getNiuLoginConfig(];
        if (config.username == res.username) {
            res.signature = config.signature || "";
  }

  /**
   * registerAccount
   * 对应 PHP: CoreNiuSmsService_core::registerAccount()
   * 逻辑类型: undefined - undefined
   */
  async registerAccount(params: any) {
    // 基于PHP真实逻辑: registerAccount
    // PHP原文: $res = (new HttpHelper())->post($this->niushop_url_prefix . self::ACCOUNT_REGISTER_URL, $params);         return $res;     }      /**      * 登录牛云短信子账号...
const res = this.httpHelperService.post(this.niushop_url_prefix . self.ACCOUNT_REGISTER_URL, params);
        return res;
    }

    /**
     * 登录牛云短信子账号
     * @param params
     * @return mixed
     */
    async loginAccount(params)
    {
        const url = this.niushop_url_prefix . sprintf(self.LOGIN_ACCOUNT_URL, params.username];
        const res = this.httpHelperService.post(url, params);
        return res;
    }

    /**
     * 获取牛云短信子账号信息
     * @param username
     * @return mixed
     */
    async accountInfo(username)
    {
        const url = this.niushop_url_prefix . sprintf(self.ACCOUNT_INFO_URL, username];
        const res = this.httpHelperService.get(url);
        const config = this.setSiteId(this.site_id).getNiuLoginConfig(];
        if (config.username == res.username) {
            res.signature = config.signature || "";
  }

  /**
   * loginAccount
   * 对应 PHP: CoreNiuSmsService_core::loginAccount()
   * 逻辑类型: undefined - undefined
   */
  async loginAccount(params: any) {
    // 基于PHP真实逻辑: loginAccount
    // PHP原文: $url = $this->niushop_url_prefix . sprintf(self::LOGIN_ACCOUNT_URL, $params['username']);         $res = (new HttpHelper())->post($url, $params);     ...
const url = this.niushop_url_prefix . sprintf(self.LOGIN_ACCOUNT_URL, params.username];
        const res = this.httpHelperService.post(url, params);
        return res;
    }

    /**
     * 获取牛云短信子账号信息
     * @param username
     * @return mixed
     */
    async accountInfo(username)
    {
        const url = this.niushop_url_prefix . sprintf(self.ACCOUNT_INFO_URL, username];
        const res = this.httpHelperService.get(url);
        const config = this.setSiteId(this.site_id).getNiuLoginConfig(];
        if (config.username == res.username) {
            res.signature = config.signature || "";
  }

  /**
   * accountInfo
   * 对应 PHP: CoreNiuSmsService_core::accountInfo()
   * 逻辑类型: undefined - undefined
   */
  async accountInfo(username: any) {
    // 基于PHP真实逻辑: accountInfo
    // PHP原文: $url = $this->niushop_url_prefix . sprintf(self::ACCOUNT_INFO_URL, $username);         $res = (new HttpHelper())->get($url);         $config = $this->...
const url = this.niushop_url_prefix . sprintf(self.ACCOUNT_INFO_URL, username];
        const res = this.httpHelperService.get(url);
        const config = this.setSiteId(this.site_id).getNiuLoginConfig(];
        if (config.username == res.username) {
            res.signature = config.signature || "";
  }

  /**
   * accountSendList
   * 对应 PHP: CoreNiuSmsService_core::accountSendList()
   * 逻辑类型: undefined - undefined
   */
  async accountSendList(username: any, params: any) {
    // 基于PHP真实逻辑: accountSendList
    // PHP原文: $url = $this->niushop_url_prefix . sprintf(self::ACCOUNT_SEND_LIST_URL, $username);         $res = (new HttpHelper())->get($url, $this->getPageParam()...
const url = this.niushop_url_prefix . sprintf(self.ACCOUNT_SEND_LIST_URL, username);
        const res = this.httpHelperService.get(url, this.getPageParam() + params];
        return res;
    }

    /**
     * 更新账号信息  （手机号 默认签名）
     * @param username
     * @param params
     * @return mixed
     */
    async editAccount(username, params)
    {
        const url = this.niushop_url_prefix . sprintf(self.ACCOUNT_EDIT_URL, username];
        const res = this.httpHelperService.put(url, params);
        return res;
    }

    /**
     * 重置密码
     * @param username
     * @param params
     * @return mixed
     */
    async resetPassword(username, params)
    {
        const url = this.niushop_url_prefix . sprintf(self.RESET_PASSWORD_URL, username];
        const res = this.httpHelperService.put(url, params);
        return res;
    }


    /**********************签名处理*********************/

    /**
     * 获取签名列表
     * @param username
     * @return mixed
     */
    async signList(username)
    {
        const url = this.niushop_url_prefix . sprintf(self.SIGN_LIST_URL, username);
        const res = this.httpHelperService.get(url, this.getPageParam()];
        return res;
    }

    /**
     * 获取签名信息
     * @param username
     * @param signature
     * @return mixed
     */
    async signInfo(username, signature)
    {
        const url = this.niushop_url_prefix . sprintf(self.SIGN_INFO_URL, username);
        const res = this.httpHelperService.get(url, [signature: signature)];
        return res;
    }

    /**
     * 报备签名
     * @param username
     * @param params
     * @return mixed
     */
    async signCreate(username, params)
    {
        const url = this.niushop_url_prefix . sprintf(self.SIGN_ADD_URL, username];
        const res = this.httpHelperService.post(url, params);
        return res;
    }

    /**
     * 报备签名-删除
     * @param username
     * @param params
     * @return mixed
     * @throws \BusinessException
     */
    async signDelete(username, params)
    {
        const time = time(];
        request.tKey = time;
        request.password = md5(md5(params.password) . time];
        request.username = username;
        request.remark = params.remark || '';
        request.signatureList = params.signatures;
        const url = "https://api-shss.zthysms.com/sms/v1/sign/delete";
        const res = this.httpHelperService.httpRequest('POST', url, request);
        if (res.code != 200) {
            throw new \BusinessException(res.msg);
  }

  /**
   * editAccount
   * 对应 PHP: CoreNiuSmsService_core::editAccount()
   * 逻辑类型: undefined - undefined
   */
  async editAccount(username: any, params: any) {
    // 基于PHP真实逻辑: editAccount
    // PHP原文: $url = $this->niushop_url_prefix . sprintf(self::ACCOUNT_EDIT_URL, $username);         $res = (new HttpHelper())->put($url, $params);         return $...
const url = this.niushop_url_prefix . sprintf(self.ACCOUNT_EDIT_URL, username];
        const res = this.httpHelperService.put(url, params);
        return res;
    }

    /**
     * 重置密码
     * @param username
     * @param params
     * @return mixed
     */
    async resetPassword(username, params)
    {
        const url = this.niushop_url_prefix . sprintf(self.RESET_PASSWORD_URL, username];
        const res = this.httpHelperService.put(url, params);
        return res;
    }


    /**********************签名处理*********************/

    /**
     * 获取签名列表
     * @param username
     * @return mixed
     */
    async signList(username)
    {
        const url = this.niushop_url_prefix . sprintf(self.SIGN_LIST_URL, username);
        const res = this.httpHelperService.get(url, this.getPageParam()];
        return res;
    }

    /**
     * 获取签名信息
     * @param username
     * @param signature
     * @return mixed
     */
    async signInfo(username, signature)
    {
        const url = this.niushop_url_prefix . sprintf(self.SIGN_INFO_URL, username);
        const res = this.httpHelperService.get(url, [signature: signature)];
        return res;
    }

    /**
     * 报备签名
     * @param username
     * @param params
     * @return mixed
     */
    async signCreate(username, params)
    {
        const url = this.niushop_url_prefix . sprintf(self.SIGN_ADD_URL, username];
        const res = this.httpHelperService.post(url, params);
        return res;
    }

    /**
     * 报备签名-删除
     * @param username
     * @param params
     * @return mixed
     * @throws \BusinessException
     */
    async signDelete(username, params)
    {
        const time = time(];
        request.tKey = time;
        request.password = md5(md5(params.password) . time];
        request.username = username;
        request.remark = params.remark || '';
        request.signatureList = params.signatures;
        const url = "https://api-shss.zthysms.com/sms/v1/sign/delete";
        const res = this.httpHelperService.httpRequest('POST', url, request);
        if (res.code != 200) {
            throw new \BusinessException(res.msg);
  }

  /**
   * resetPassword
   * 对应 PHP: CoreNiuSmsService_core::resetPassword()
   * 逻辑类型: undefined - undefined
   */
  async resetPassword(username: any, params: any) {
    // 基于PHP真实逻辑: resetPassword
    // PHP原文: $url = $this->niushop_url_prefix . sprintf(self::RESET_PASSWORD_URL, $username);         $res = (new HttpHelper())->put($url, $params);         return...
const url = this.niushop_url_prefix . sprintf(self.RESET_PASSWORD_URL, username];
        const res = this.httpHelperService.put(url, params);
        return res;
    }


    /**********************签名处理*********************/

    /**
     * 获取签名列表
     * @param username
     * @return mixed
     */
    async signList(username)
    {
        const url = this.niushop_url_prefix . sprintf(self.SIGN_LIST_URL, username);
        const res = this.httpHelperService.get(url, this.getPageParam()];
        return res;
    }

    /**
     * 获取签名信息
     * @param username
     * @param signature
     * @return mixed
     */
    async signInfo(username, signature)
    {
        const url = this.niushop_url_prefix . sprintf(self.SIGN_INFO_URL, username);
        const res = this.httpHelperService.get(url, [signature: signature)];
        return res;
    }

    /**
     * 报备签名
     * @param username
     * @param params
     * @return mixed
     */
    async signCreate(username, params)
    {
        const url = this.niushop_url_prefix . sprintf(self.SIGN_ADD_URL, username];
        const res = this.httpHelperService.post(url, params);
        return res;
    }

    /**
     * 报备签名-删除
     * @param username
     * @param params
     * @return mixed
     * @throws \BusinessException
     */
    async signDelete(username, params)
    {
        const time = time(];
        request.tKey = time;
        request.password = md5(md5(params.password) . time];
        request.username = username;
        request.remark = params.remark || '';
        request.signatureList = params.signatures;
        const url = "https://api-shss.zthysms.com/sms/v1/sign/delete";
        const res = this.httpHelperService.httpRequest('POST', url, request);
        if (res.code != 200) {
            throw new \BusinessException(res.msg);
  }

  /**
   * signList
   * 对应 PHP: CoreNiuSmsService_core::signList()
   * 逻辑类型: undefined - undefined
   */
  async signList(username: any) {
    // 基于PHP真实逻辑: signList
    // PHP原文: $url = $this->niushop_url_prefix . sprintf(self::SIGN_LIST_URL, $username);         $res = (new HttpHelper())->get($url, $this->getPageParam());      ...
const url = this.niushop_url_prefix . sprintf(self.SIGN_LIST_URL, username);
        const res = this.httpHelperService.get(url, this.getPageParam()];
        return res;
    }

    /**
     * 获取签名信息
     * @param username
     * @param signature
     * @return mixed
     */
    async signInfo(username, signature)
    {
        const url = this.niushop_url_prefix . sprintf(self.SIGN_INFO_URL, username);
        const res = this.httpHelperService.get(url, [signature: signature)];
        return res;
    }

    /**
     * 报备签名
     * @param username
     * @param params
     * @return mixed
     */
    async signCreate(username, params)
    {
        const url = this.niushop_url_prefix . sprintf(self.SIGN_ADD_URL, username];
        const res = this.httpHelperService.post(url, params);
        return res;
    }

    /**
     * 报备签名-删除
     * @param username
     * @param params
     * @return mixed
     * @throws \BusinessException
     */
    async signDelete(username, params)
    {
        const time = time(];
        request.tKey = time;
        request.password = md5(md5(params.password) . time];
        request.username = username;
        request.remark = params.remark || '';
        request.signatureList = params.signatures;
        const url = "https://api-shss.zthysms.com/sms/v1/sign/delete";
        const res = this.httpHelperService.httpRequest('POST', url, request);
        if (res.code != 200) {
            throw new \BusinessException(res.msg);
  }

  /**
   * signInfo
   * 对应 PHP: CoreNiuSmsService_core::signInfo()
   * 逻辑类型: undefined - undefined
   */
  async signInfo(username: any, signature: any) {
    // 基于PHP真实逻辑: signInfo
    // PHP原文: $url = $this->niushop_url_prefix . sprintf(self::SIGN_INFO_URL, $username);         $res = (new HttpHelper())->get($url, ['signature' => $signature]);...
const url = this.niushop_url_prefix . sprintf(self.SIGN_INFO_URL, username);
        const res = this.httpHelperService.get(url, [signature: signature)];
        return res;
    }

    /**
     * 报备签名
     * @param username
     * @param params
     * @return mixed
     */
    async signCreate(username, params)
    {
        const url = this.niushop_url_prefix . sprintf(self.SIGN_ADD_URL, username];
        const res = this.httpHelperService.post(url, params);
        return res;
    }

    /**
     * 报备签名-删除
     * @param username
     * @param params
     * @return mixed
     * @throws \BusinessException
     */
    async signDelete(username, params)
    {
        const time = time(];
        request.tKey = time;
        request.password = md5(md5(params.password) . time];
        request.username = username;
        request.remark = params.remark || '';
        request.signatureList = params.signatures;
        const url = "https://api-shss.zthysms.com/sms/v1/sign/delete";
        const res = this.httpHelperService.httpRequest('POST', url, request);
        if (res.code != 200) {
            throw new \BusinessException(res.msg);
  }

  /**
   * signCreate
   * 对应 PHP: CoreNiuSmsService_core::signCreate()
   * 逻辑类型: undefined - undefined
   */
  async signCreate(username: any, params: any) {
    // 基于PHP真实逻辑: signCreate
    // PHP原文: $url = $this->niushop_url_prefix . sprintf(self::SIGN_ADD_URL, $username);         $res = (new HttpHelper())->post($url, $params);         return $res...
const url = this.niushop_url_prefix . sprintf(self.SIGN_ADD_URL, username];
        const res = this.httpHelperService.post(url, params);
        return res;
    }

    /**
     * 报备签名-删除
     * @param username
     * @param params
     * @return mixed
     * @throws \BusinessException
     */
    async signDelete(username, params)
    {
        const time = time(];
        request.tKey = time;
        request.password = md5(md5(params.password) . time];
        request.username = username;
        request.remark = params.remark || '';
        request.signatureList = params.signatures;
        const url = "https://api-shss.zthysms.com/sms/v1/sign/delete";
        const res = this.httpHelperService.httpRequest('POST', url, request);
        if (res.code != 200) {
            throw new \BusinessException(res.msg);
  }

  /**
   * signDelete
   * 对应 PHP: CoreNiuSmsService_core::signDelete()
   * 逻辑类型: undefined - undefined
   */
  async signDelete(username: any, params: any) {
    // 基于PHP真实逻辑: signDelete
    // PHP原文: $time = time();         $request['tKey'] = $time;         $request['password'] = md5(md5($params['password']) . $time);         $request['username'] =...
const time = time(];
        request.tKey = time;
        request.password = md5(md5(params.password) . time];
        request.username = username;
        request.remark = params.remark || '';
        request.signatureList = params.signatures;
        const url = "https://api-shss.zthysms.com/sms/v1/sign/delete";
        const res = this.httpHelperService.httpRequest('POST', url, request);
        if (res.code != 200) {
            throw new \BusinessException(res.msg);
  }

  /**
   * templateList
   * 对应 PHP: CoreNiuSmsService_core::templateList()
   * 逻辑类型: undefined - undefined
   */
  async templateList(username: any, params: any) {
    // 基于PHP真实逻辑: templateList
    // PHP原文: $params = array_merge($params, $this->getPageParam());         $params['limit'] = $params['limit'] ?? 100;         $url = $this->niushop_url_prefix . ...
const params = Object.assign(params, this.getPageParam()];
        params.limit = params.limit || 100;
        const url = this.niushop_url_prefix . sprintf(self.TEMPLATE_LIST_URL, username];
        const res = this.httpHelperService.get(url, params);
        return res;
    }

    /**
     * 获取模版详情
     * @param username
     * @param tem_id
     * @return mixed
     */
    async templateInfo(username, tem_id)
    {
        const url = this.niushop_url_prefix . sprintf(self.TEMPLATE_INFO_URL, username);
        const res = this.httpHelperService.get(url, [
            tem_id: tem_id
        )];
        return res;
    }

    /**
     * 获取签名列表
     * @param username
     * @param params
     * @return mixed
     */
    async templateCreate(username, params)
    {
        const url = this.niushop_url_prefix . sprintf(self.TEMPLATE_ADD_URL, username];
        const res = this.httpHelperService.post(url, params);
        return res;
    }

    /**
     * 删除模版
     * @param username
     * @param params
     * @return mixed
     * @throws \BusinessException
     */
    async templateDelete(username, params)
    {
        const time = time(];
        request.tKey = time;
        request.password = md5(md5(params.password) . time];
        request.username = username;
        request.temId = params.template_id || '';
        const url = "https://api-shss.zthysms.com/sms/v2/template/delete";
        const res = this.httpHelperService.httpRequest('POST', url, request);
        if (res.code != 200) {
            throw new \BusinessException('ZT' . res.code  + ':" . res.msg);
  }

  /**
   * templateInfo
   * 对应 PHP: CoreNiuSmsService_core::templateInfo()
   * 逻辑类型: undefined - undefined
   */
  async templateInfo(username: any, tem_id: any) {
    // 基于PHP真实逻辑: templateInfo
    // PHP原文: $url = $this->niushop_url_prefix . sprintf(self::TEMPLATE_INFO_URL, $username);         $res = (new HttpHelper())->get($url, [             'tem_id' =>...
const url = this.niushop_url_prefix . sprintf(self.TEMPLATE_INFO_URL, username);
        const res = this.httpHelperService.get(url, [
            tem_id: tem_id
        )];
        return res;
    }

    /**
     * 获取签名列表
     * @param username
     * @param params
     * @return mixed
     */
    async templateCreate(username, params)
    {
        const url = this.niushop_url_prefix . sprintf(self.TEMPLATE_ADD_URL, username];
        const res = this.httpHelperService.post(url, params);
        return res;
    }

    /**
     * 删除模版
     * @param username
     * @param params
     * @return mixed
     * @throws \BusinessException
     */
    async templateDelete(username, params)
    {
        const time = time(];
        request.tKey = time;
        request.password = md5(md5(params.password) . time];
        request.username = username;
        request.temId = params.template_id || '';
        const url = "https://api-shss.zthysms.com/sms/v2/template/delete";
        const res = this.httpHelperService.httpRequest('POST', url, request);
        if (res.code != 200) {
            throw new \BusinessException('ZT' . res.code  + ':" . res.msg);
  }

  /**
   * templateCreate
   * 对应 PHP: CoreNiuSmsService_core::templateCreate()
   * 逻辑类型: undefined - undefined
   */
  async templateCreate(username: any, params: any) {
    // 基于PHP真实逻辑: templateCreate
    // PHP原文: $url = $this->niushop_url_prefix . sprintf(self::TEMPLATE_ADD_URL, $username);         $res = (new HttpHelper())->post($url, $params);         return ...
const url = this.niushop_url_prefix . sprintf(self.TEMPLATE_ADD_URL, username];
        const res = this.httpHelperService.post(url, params);
        return res;
    }

    /**
     * 删除模版
     * @param username
     * @param params
     * @return mixed
     * @throws \BusinessException
     */
    async templateDelete(username, params)
    {
        const time = time(];
        request.tKey = time;
        request.password = md5(md5(params.password) . time];
        request.username = username;
        request.temId = params.template_id || '';
        const url = "https://api-shss.zthysms.com/sms/v2/template/delete";
        const res = this.httpHelperService.httpRequest('POST', url, request);
        if (res.code != 200) {
            throw new \BusinessException('ZT' . res.code  + ':" . res.msg);
  }

  /**
   * templateDelete
   * 对应 PHP: CoreNiuSmsService_core::templateDelete()
   * 逻辑类型: undefined - undefined
   */
  async templateDelete(username: any, params: any) {
    // 基于PHP真实逻辑: templateDelete
    // PHP原文: $time = time();         $request['tKey'] = $time;         $request['password'] = md5(md5($params['password']) . $time);         $request['username'] =...
const time = time(];
        request.tKey = time;
        request.password = md5(md5(params.password) . time];
        request.username = username;
        request.temId = params.template_id || '';
        const url = "https://api-shss.zthysms.com/sms/v2/template/delete";
        const res = this.httpHelperService.httpRequest('POST', url, request);
        if (res.code != 200) {
            throw new \BusinessException('ZT' . res.code  + ':" . res.msg);
  }

  /**
   * orderList
   * 对应 PHP: CoreNiuSmsService_core::orderList()
   * 逻辑类型: undefined - undefined
   */
  async orderList(username: any, params: any) {
    // 基于PHP真实逻辑: orderList
    // PHP原文: $url = $this->niushop_url_prefix . sprintf(self::ORDER_LIST_URL, $username);         $res = (new HttpHelper())->get($url, $this->getPageParam() + $par...
const url = this.niushop_url_prefix . sprintf(self.ORDER_LIST_URL, username);
        const res = this.httpHelperService.get(url, this.getPageParam() + params];
        return res;
    }

    /**
     * 获取订单详情
     * @param username
     * @param out_trade_no
     * @return mixed
     */
    async orderInfo(username, out_trade_no)
    {
        const url = this.niushop_url_prefix . sprintf(self.ORDER_INFO_URL, username, out_trade_no];
        const res = this.httpHelperService.get(url);
        return res;
    }

    /**
     * 获取订单状态
     * @param username
     * @param out_trade_no
     * @return mixed
     */
    async orderStatus(username, out_trade_no)
    {
        const url = this.niushop_url_prefix . sprintf(self.ORDER_STATUS_URL, username, out_trade_no];
        const res = this.httpHelperService.get(url);
        return res;
    }

    /**
     * 创建订单
     * @param username
     * @param params
     * @return mixed
     */
    async orderCreate(username, params)
    {
        const url = this.niushop_url_prefix . sprintf(self.ORDER_CREATE_URL, username];
        const res = this.httpHelperService.post(url, params);
        return res;
    }

    /**
     * 创建订单
     * @param username
     * @param params
     * @return mixed
     */
    async calculate(username, params)
    {
        const url = this.niushop_url_prefix . sprintf(self.ORDER_CALCULATE_URL, username];
        const res = this.httpHelperService.post(url, params);
        return res;
    }

    /**
     * 获取订单支付信息
     * @param username
     * @param params
     * @return mixed
     */
    async orderPayInfo(username, params)
    {
        // 判断是否为https协议
        const protocol = (typeof _SERVER.HTTPS) && _SERVER.HTTPS === 'on') ? 'https' : 'http';
        // 获取域名（含端口）
        const host = _SERVER.HTTP_HOST;
        // 组合成全域名
        const return_url = protocol  + '://' . host  + '/site/setting/sms/pay";

        const url = this.niushop_url_prefix . sprintf(self.ORDER_PAY_URL, username];
        params.notify_url = this.niushop_url_prefix . self.ORDER_NOTIFY_URL;
        //TODO.待添加支付结果页面
        params.return_url = return_url;
        const res = this.httpHelperService.post(url, params);
        return res;
    }
}
  }

  /**
   * orderInfo
   * 对应 PHP: CoreNiuSmsService_core::orderInfo()
   * 逻辑类型: undefined - undefined
   */
  async orderInfo(username: any, out_trade_no: any) {
    // 基于PHP真实逻辑: orderInfo
    // PHP原文: $url = $this->niushop_url_prefix . sprintf(self::ORDER_INFO_URL, $username, $out_trade_no);         $res = (new HttpHelper())->get($url);         retu...
const url = this.niushop_url_prefix . sprintf(self.ORDER_INFO_URL, username, out_trade_no];
        const res = this.httpHelperService.get(url);
        return res;
    }

    /**
     * 获取订单状态
     * @param username
     * @param out_trade_no
     * @return mixed
     */
    async orderStatus(username, out_trade_no)
    {
        const url = this.niushop_url_prefix . sprintf(self.ORDER_STATUS_URL, username, out_trade_no];
        const res = this.httpHelperService.get(url);
        return res;
    }

    /**
     * 创建订单
     * @param username
     * @param params
     * @return mixed
     */
    async orderCreate(username, params)
    {
        const url = this.niushop_url_prefix . sprintf(self.ORDER_CREATE_URL, username];
        const res = this.httpHelperService.post(url, params);
        return res;
    }

    /**
     * 创建订单
     * @param username
     * @param params
     * @return mixed
     */
    async calculate(username, params)
    {
        const url = this.niushop_url_prefix . sprintf(self.ORDER_CALCULATE_URL, username];
        const res = this.httpHelperService.post(url, params);
        return res;
    }

    /**
     * 获取订单支付信息
     * @param username
     * @param params
     * @return mixed
     */
    async orderPayInfo(username, params)
    {
        // 判断是否为https协议
        const protocol = (typeof _SERVER.HTTPS) && _SERVER.HTTPS === 'on') ? 'https' : 'http';
        // 获取域名（含端口）
        const host = _SERVER.HTTP_HOST;
        // 组合成全域名
        const return_url = protocol  + '://' . host  + '/site/setting/sms/pay";

        const url = this.niushop_url_prefix . sprintf(self.ORDER_PAY_URL, username];
        params.notify_url = this.niushop_url_prefix . self.ORDER_NOTIFY_URL;
        //TODO.待添加支付结果页面
        params.return_url = return_url;
        const res = this.httpHelperService.post(url, params);
        return res;
    }
}
  }

  /**
   * orderStatus
   * 对应 PHP: CoreNiuSmsService_core::orderStatus()
   * 逻辑类型: undefined - undefined
   */
  async orderStatus(username: any, out_trade_no: any) {
    // 基于PHP真实逻辑: orderStatus
    // PHP原文: $url = $this->niushop_url_prefix . sprintf(self::ORDER_STATUS_URL, $username, $out_trade_no);         $res = (new HttpHelper())->get($url);         re...
const url = this.niushop_url_prefix . sprintf(self.ORDER_STATUS_URL, username, out_trade_no];
        const res = this.httpHelperService.get(url);
        return res;
    }

    /**
     * 创建订单
     * @param username
     * @param params
     * @return mixed
     */
    async orderCreate(username, params)
    {
        const url = this.niushop_url_prefix . sprintf(self.ORDER_CREATE_URL, username];
        const res = this.httpHelperService.post(url, params);
        return res;
    }

    /**
     * 创建订单
     * @param username
     * @param params
     * @return mixed
     */
    async calculate(username, params)
    {
        const url = this.niushop_url_prefix . sprintf(self.ORDER_CALCULATE_URL, username];
        const res = this.httpHelperService.post(url, params);
        return res;
    }

    /**
     * 获取订单支付信息
     * @param username
     * @param params
     * @return mixed
     */
    async orderPayInfo(username, params)
    {
        // 判断是否为https协议
        const protocol = (typeof _SERVER.HTTPS) && _SERVER.HTTPS === 'on') ? 'https' : 'http';
        // 获取域名（含端口）
        const host = _SERVER.HTTP_HOST;
        // 组合成全域名
        const return_url = protocol  + '://' . host  + '/site/setting/sms/pay";

        const url = this.niushop_url_prefix . sprintf(self.ORDER_PAY_URL, username];
        params.notify_url = this.niushop_url_prefix . self.ORDER_NOTIFY_URL;
        //TODO.待添加支付结果页面
        params.return_url = return_url;
        const res = this.httpHelperService.post(url, params);
        return res;
    }
}
  }

  /**
   * orderCreate
   * 对应 PHP: CoreNiuSmsService_core::orderCreate()
   * 逻辑类型: undefined - undefined
   */
  async orderCreate(username: any, params: any) {
    // 基于PHP真实逻辑: orderCreate
    // PHP原文: $url = $this->niushop_url_prefix . sprintf(self::ORDER_CREATE_URL, $username);         $res = (new HttpHelper())->post($url, $params);         return ...
const url = this.niushop_url_prefix . sprintf(self.ORDER_CREATE_URL, username];
        const res = this.httpHelperService.post(url, params);
        return res;
    }

    /**
     * 创建订单
     * @param username
     * @param params
     * @return mixed
     */
    async calculate(username, params)
    {
        const url = this.niushop_url_prefix . sprintf(self.ORDER_CALCULATE_URL, username];
        const res = this.httpHelperService.post(url, params);
        return res;
    }

    /**
     * 获取订单支付信息
     * @param username
     * @param params
     * @return mixed
     */
    async orderPayInfo(username, params)
    {
        // 判断是否为https协议
        const protocol = (typeof _SERVER.HTTPS) && _SERVER.HTTPS === 'on') ? 'https' : 'http';
        // 获取域名（含端口）
        const host = _SERVER.HTTP_HOST;
        // 组合成全域名
        const return_url = protocol  + '://' . host  + '/site/setting/sms/pay";

        const url = this.niushop_url_prefix . sprintf(self.ORDER_PAY_URL, username];
        params.notify_url = this.niushop_url_prefix . self.ORDER_NOTIFY_URL;
        //TODO.待添加支付结果页面
        params.return_url = return_url;
        const res = this.httpHelperService.post(url, params);
        return res;
    }
}
  }

  /**
   * calculate
   * 对应 PHP: CoreNiuSmsService_core::calculate()
   * 逻辑类型: undefined - undefined
   */
  async calculate(username: any, params: any) {
    // 基于PHP真实逻辑: calculate
    // PHP原文: $url = $this->niushop_url_prefix . sprintf(self::ORDER_CALCULATE_URL, $username);         $res = (new HttpHelper())->post($url, $params);         retu...
const url = this.niushop_url_prefix . sprintf(self.ORDER_CALCULATE_URL, username];
        const res = this.httpHelperService.post(url, params);
        return res;
    }

    /**
     * 获取订单支付信息
     * @param username
     * @param params
     * @return mixed
     */
    async orderPayInfo(username, params)
    {
        // 判断是否为https协议
        const protocol = (typeof _SERVER.HTTPS) && _SERVER.HTTPS === 'on') ? 'https' : 'http';
        // 获取域名（含端口）
        const host = _SERVER.HTTP_HOST;
        // 组合成全域名
        const return_url = protocol  + '://' . host  + '/site/setting/sms/pay";

        const url = this.niushop_url_prefix . sprintf(self.ORDER_PAY_URL, username];
        params.notify_url = this.niushop_url_prefix . self.ORDER_NOTIFY_URL;
        //TODO.待添加支付结果页面
        params.return_url = return_url;
        const res = this.httpHelperService.post(url, params);
        return res;
    }
}
  }

  /**
   * orderPayInfo
   * 对应 PHP: CoreNiuSmsService_core::orderPayInfo()
   * 逻辑类型: undefined - undefined
   */
  async orderPayInfo(username: any, params: any) {
    // 基于PHP真实逻辑: orderPayInfo
    // PHP原文: // 判断是否为https协议         $protocol = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') ? 'https' : 'http';         // 获取域名（含端口）         $host = ...
// 判断是否为https协议
        const protocol = (typeof _SERVER.HTTPS) && _SERVER.HTTPS === 'on') ? 'https' : 'http';
        // 获取域名（含端口）
        const host = _SERVER.HTTP_HOST;
        // 组合成全域名
        const return_url = protocol  + '://' . host  + '/site/setting/sms/pay";

        const url = this.niushop_url_prefix . sprintf(self.ORDER_PAY_URL, username];
        params.notify_url = this.niushop_url_prefix . self.ORDER_NOTIFY_URL;
        //TODO.待添加支付结果页面
        params.return_url = return_url;
        const res = this.httpHelperService.post(url, params);
        return res;
    }
}
  }
}
